// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import App from './App.vue'
import router from './router'
import store from './store'
import * as filters from './filter'
import './assets/styles/common.css'
import paginate from 'components/common/paginate'
import 'src/router/handle'

Vue.use(ElementUI)
Vue.component('paginate', paginate)
Vue.prototype.timeFormat = filters.timeFormat
Vue.prototype.listRole = (val) => { // 权限判断函数 params:val路由名称
  let routeLists = router.options.routes
  if (store.getters.getRole) { // 非管理员登录
    let hasRoute = false
    routeLists.some(route => {
      if (route.children && route.children.length) {
        route.children.some(child => {
          if (child.meta.name === val) {
            hasRoute = true
            return true
          }
        })
      } else {
        hasRoute = route.meta.name === val
      }
      return hasRoute
    })
    return hasRoute
  } else { // 管理员登录
    return true
  }
}

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

/* eslint-disable no-new */
const appVue = new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')

window.$message = appVue.$message
